<!--
 * @Author: your name
 * @Date: 2022-03-09 14:05:25
 * @LastEditTime: 2022-03-09 14:21:19
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day09\4-DOM0级事件dom2级事件.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload=function(){
            var btn=document.getElementById('btn');
            //DOM 0级事件  不可追加事件
            btn.onclick=function(){
                console.log('我被点击了一下');
            }
            btn.onclick=function(){
                alert('我被点击了一下');
            }
            //DOM 事件的解绑
            btn.onclick=null;

            //dom2级事件
            function  handler1(){
                alert('1')
            }
            function handler2(){
                alert('2')
            }
            btn.addEventListener('click',handler1,false);
            btn.addEventListener('click',handler2,false);
            btn.removeEventListener('click',handler1)
        } ;
       
    </script>
</head>
<body>
    <button id="btn">点击我 </button>
</body>
</html>